<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>lxp_test</title>
		
    <!-- bootstrap.css -->
    <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">  
    <!-- jquery -->
    <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
    <!-- bootstrap.js -->
    <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  	<!-- angular -->
  	<script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
  	<!-- jquery-validation 表单验证-->
  	<script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/jquery.validate.min.js"></script>
		<script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/localization/messages_zh.js"></script>

  </head>
  <script>
  	app = angular.module("app",[]);
  	app.controller("ctrl",function($scope){
  		$scope.arr = [1,2,3,4,5];
  		$scope.brr = ["a","b","c"];
  		$scope.cc = function(v){
  			console.log(v)
  			  var n = $scope.arr.length+1;
  			  $scope.arr.push(n)
  		}
  		
  		
  	});
  	app.directive("dd",function(){
	return {
		restrict:"AE",
		template:'<div>ddd</div>',
		replace:true,
		link:function(scope,element,attr){
				scope.add = function(){
  			  var n = scope.arr.length+1;
  			  scope.arr.push(n)
  		}
		}
	}
});
  </script>
  <body ng-app="app" ng-controller="ctrl">
    	<div ng-click="cc(a+$index)" style="width: 200px;height: 200px;border: 1px solid red;margin-bottom: 10px;" ng-repeat="a in arr">{{a}}{{$index}}
    			<div ng-if="a==2" ng-repeat="b in brr">{{b}}{{$index}}
    					<div>{{$index}}</div>
    			</div>
    		
    	</div>

   		<button dd >xxxx</button>
  </body>
</html>